export default {
  name: 'Product',

  data() {
    return {
      productList: [],
      index: 0,
      product_1: '',
      product_2: '',
      product_3: ''
    };
  },
  onLoad(option) {
    uni.showLoading();
    uni.$API.Product
      .getPlanCompare({ type: option.id })
      .then(res => {
        this.productList = res.data.planCompare;
        uni.hideLoading();
      })
      .catch(error => {
        uni.hideLoading();
      });
    //this.productList = require(`./product-${option.id}.json`);
  },
  methods: {
    product1Change(e) {
      const index = e.target.value;
      this.product_1 = this.productList[index];
    },
    product2Change(e) {
      const index = e.target.value;
      this.product_2 = this.productList[index];
    },
    product3Change(e) {
      const index = e.target.value;
      this.product_3 = this.productList[index];
    },
    gotoAnalysisPage() {
      const display = this.$route.query.display;
      const productList = [];
      if (this.product_1) {
        productList.push(this.product_1);
      }
      if (this.product_2) {
        productList.push(this.product_2);
      }
      if (this.product_3) {
        productList.push(this.product_3);
      }
      if (productList.length <= 1) {
        uni.$co.Fun.showToast('请选择2个以上的产品进行对比');
      } else {
        uni.sessionStorage.set('PRODUCTG_LIST', productList);
        uni.navigateTo({
          url: `pages/analysis/index?display=${display}`
        });
      }
    }
  }
};
